(defun copy-line()
  (interactive)
  (let (p1 p2 myLine)
    (setq p1 (line-beginning-position) )
    (setq p2 (line-end-position) )
    (setq myLine (buffer-substring-no-properties p1 p2))
    (kill-new myLine)
    )
)

(defun kill-blank()
  (interactive)
  (skip-chars-backward " \t\n")
  (forward-char)
  (skip-chars-forward " \t")
  (let ((search-end (+ 1 (point))))
    (backward-char)
    (skip-chars-backward " \t\n")
    ;(read-char "start delete")
    ;(read-char (format "search-end:%d" search-end))
    (if (search-forward "\n" search-end t)
        (progn (skip-chars-backward " \t\n")
               (set-mark (point))
               (skip-chars-forward " \t\n")
               (delete-region (region-beginning) (region-end))
               (insert "\n"))
        (progn (skip-chars-backward " \t\n")
               (set-mark (point))
               (skip-chars-forward " \t\n")
               (delete-region (region-beginning) (region-end))
               (insert " "))))
)

(defun force-my-cpp-style()
  (interactive)
  ;; save original cursor position
  (setq original_pos (point))

  ;; deal with the ugly curly brackets
  ;; move cursor to beginning of buffer
  (goto-char (point-min))
  (while (re-search-forward "\n *{" nil t)
    (replace-match " {"))
  ;; deal with the stupid blank before '['
  (goto-char (point-min))
  (while (re-search-forward " +\\[" nil t)
    (replace-match "["))
  ;; deal with multiple blank lines
  (goto-char (point-min))
  (while (re-search-forward "\n\n+" nil t)
    (replace-match "\n\n")
   )
  ;; deal with else in new line
  (goto-char (point-min))
  (while (re-search-forward "} *?\n *?else" nil t)
    (replace-match "\n} else")
   )
  ;; indent the whole buffer
  (indent-region (point-min) (point-max))
  ;; move cursor back to original position
  (goto-char original_pos)
)
